/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package servlet;

import dao.MemberDao;
import entity.Member;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import service.AddDiscuss;

/**
 *
 * @author zhang
 */
@WebServlet("/ds")
public class DiscussServlet extends HttpServlet{

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        String name=(String)req.getSession().getAttribute("username");
        Member member=new MemberDao().getMemberByName(name);
        int bookId=Integer.parseInt(req.getParameter("bookid"));
        String comment=req.getParameter("discuss");
        
        Boolean bool=new AddDiscuss().addDiscuss(member.getId(),bookId,comment);
        
        resp.setContentType("text/html;charset=utf-8");
        if(bool==false){
            resp.getWriter().println("<h1>评价失败！</h1>");
        }else{
            resp.getWriter().println("<h1>评论成功！</h1>");
        }
        resp.getWriter().println("<a href='gbbi?id="+bookId+"'>返回</a>");
    }

    
    
    
}
